package com.wanxi.step07test.controller;


import com.wanxi.step07test.dto.ResultDTO;
import com.wanxi.step07test.model.NewsModel;
import com.wanxi.step07test.service.impl.NewsServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@CrossOrigin
public class NewsController {

    @Autowired
    private NewsServiceImpl newsService;

    @PreAuthorize("hasAuthority('news:findAll')")
    @RequestMapping("/back/news/findAll")
    @ResponseBody
    public ResultDTO findAll(NewsModel news) {
        ResultDTO resultDTO = newsService.findAll(news);
        return resultDTO;
    }

    @PreAuthorize("hasAuthority('news:add')")
    @RequestMapping("/back/news/add")
    @ResponseBody
    public ResultDTO add(NewsModel news) {
        ResultDTO resultDTO = newsService.add(news);
        return resultDTO;
    }

    @PreAuthorize("hasAuthority('news:delete')")
    @RequestMapping("/back/news/delete")
    @ResponseBody
    public ResultDTO delete(NewsModel news) {
        ResultDTO resultDTO = newsService.delete(news);
        return resultDTO;
    }

    @PreAuthorize("hasAuthority('news:findById')")
    @RequestMapping("/back/news/findById")
    @ResponseBody
    public ResultDTO findById(NewsModel news) {
        ResultDTO resultDTO = newsService.findById(news);
        return resultDTO;
    }

    @PreAuthorize("hasAuthority('news:update')")
    @RequestMapping("/back/news/update")
    @ResponseBody
    public ResultDTO update(NewsModel news) {
        ResultDTO resultDTO = newsService.update(news);
        return resultDTO;
    }

}
